/**
 * 
 */
package edu.isistan.genetic.operators;


import java.util.Vector;

import edu.isistan.metamodel.DataType;
import edu.isistan.metamodel.Primitive;

/**
 * @author mtrotti
 *
 */
public class SuperType extends  UpCasting {

	
	/**
	 * 
	 */
	public SuperType() {
		//Only set Target Type, because isCompatible method was overwritten
		super(null, "String");
	}

	/* 
	 * Every Type could be "casting" to string
	 */
	@Override
	public boolean isCompatible(DataType aDataType) {
		return true;
	}

	/* (non-Javadoc)
	 * @see edu.isistan.genetic.operators.Operator#isEncapsulationCompatible()
	 */
	@Override
	public boolean isEncapsulationCompatible() {
		return false;
	}
	
	/* (non-Javadoc)
	 * @see Operators.Operator#mutate(edu.isistan.metamodel.DataType)
	 */
	@Override
	public Vector<DataType> mutate(Vector<DataType> aDataTypes) {
		Vector<DataType> aResultSet = new Vector<DataType>();
		for (DataType aDataType : aDataTypes){
			if (!aDataType.isCompoused()){
				aDataType.setType(this.targetType);
				aResultSet.add(aDataType);
			}else{
				Primitive primitive=new Primitive(aDataType.getName(),this.targetType,aDataType.getDoc());
				aResultSet.add(primitive);
			}
		}
		return aResultSet;
	}
	
	@Override
	public String toString() {
		return "Upcasting to supertype";
	}
}
